home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d2 / skey30.arc / MUSIC.ASM < prev    next >
Assembly Source File  |  1990-03-31  |  7KB  |  202 lines

  1.                                 title MUSIC.ASM
  2. ;Copyright (C) 1990 by B. Simon and R. M. Wilson, all rights reserved.
  3.  
  4.       ;-----------------------------------------------------------------;
  5.       ;             **  For use with STACKEY or DOS  **                 ;
  6.       ;                                                                 ;
  7.       ;  This file may be modified by assembly language programmers.    ;
  8.       ;  You may change anything in the two boxes like this one.  That  ;
  9.       ;  is, change the tempo and pitch just below, and the notes in    ;
  10.       ;  the middle of this file.  (The note data alternates: pitches   ;
  11.       ;  and note lengths.) Then assemble, link and exe2bin.  Run as a  ;
  12.       ;  com file from DOS or as STACKEY ex(music.com)                  ;
  13.       ;-----------------------------------------------------------------;
  14.  
  15. ;-----------------------;
  16. tempo=300               ;  increase to make tempo SLOWER
  17. pitch=128               ;  increase to LOWER pitch
  18. ;-----------------------;
  19.  
  20. n1=16*tempo                  ;whole note       legato (full length)
  21. n2=8*tempo                   ;half note        legato (full length)
  22. n4=4*tempo                   ;quarter note     legato (full length)
  23. n8=2*tempo                   ;eighth note      legato (full length)
  24. n16=tempo                    ;sixteenth note   legato (full length)
  25. n32=tempo/2                  ;32nd note        legato (full length)
  26.  
  27. n1d=16*tempo +4000h          ;whole note       detached (3/4 length)
  28. n2d=8*tempo  +4000h          ;half note        detached (3/4 length)
  29. n4d=4*tempo  +4000h          ;quarter note     detached (3/4 length)
  30. n8d=2*tempo  +4000h          ;eighth note      detached (3/4 length)
  31. n16d=tempo   +4000h          ;sixteenth note   detached (3/4 length)
  32. n32d=tempo/2 +4000h          ;32nd note        detached (3/4 length)
  33.  
  34. n1s=16*tempo +8000h          ;whole note       staccato  (1/2 length)
  35. n2s=8*tempo  +8000h          ;half note        staccato  (1/2 length)
  36. n4s=4*tempo  +8000h          ;quarter note     staccato  (1/2 length)
  37. n8s=2*tempo  +8000h          ;eighth note      staccato  (1/2 length)
  38. n16s=tempo   +8000h          ;sixteenth note   staccato  (1/2 length)
  39. n32s=tempo/2 +8000h          ;32nd note        staccato  (1/2 length)
  40.  
  41. rest= 0
  42.  
  43. ; Just for fun, we use "just intonation".
  44.  
  45. c0=64*pitch
  46. c1=32*pitch
  47. c2=16*pitch
  48. c3=8*pitch
  49. c4=4*pitch
  50. c5=2*pitch
  51. c6=pitch
  52.  
  53. d1=32*pitch*8/9
  54. d2=16*pitch*8/9
  55. d3=8*pitch *8/9
  56. d4=4*pitch *8/9
  57. d5=2*pitch *8/9
  58. d6=pitch   *8/9
  59.  
  60. e1=32*pitch*4/5
  61. e2=16*pitch*4/5
  62. e3=8*pitch *4/5
  63. e4=4*pitch *4/5
  64. e5=2*pitch *4/5
  65. e6=pitch   *4/5
  66.  
  67. f1=32*pitch*3/4
  68. f2=16*pitch*3/4
  69. f3=8*pitch *3/4
  70. f4=4*pitch *3/4
  71. f5=2*pitch *3/4
  72. f6=pitch   *3/4
  73.  
  74. g1=32*pitch*2/3
  75. g2=16*pitch*2/3
  76. g3=8*pitch *2/3
  77. g4=4*pitch *2/3
  78. g5=2*pitch *2/3
  79. g6=pitch   *2/3
  80.  
  81. a1=32*pitch*3/5
  82. a2=16*pitch*3/5
  83. a3=8*pitch *3/5
  84. a4=4*pitch *3/5
  85. a5=2*pitch *3/5
  86. a6=pitch   *3/5
  87.  
  88. bf1=32*pitch*9/16
  89. bf2=16*pitch*9/16
  90. bf3=8*pitch *9/16
  91. bf4=4*pitch *9/16
  92. bf5=2*pitch *9/16
  93. bf6=pitch   *9/16
  94.  
  95. b1=32*pitch*8/15
  96. b2=16*pitch*8/15
  97. b3=8*pitch *8/15
  98. b4=4*pitch *8/15
  99. b5=2*pitch *8/15
  100. b6=pitch   *8/15
  101. ;-------------------------------------------
  102.  
  103. cseg segment
  104.         assume  cs:cseg
  105.  
  106. begin:
  107.         xor dx,dx         ;Time the processor to get an approximate
  108.         push ds           ;machine independent note length.
  109.         xor ax,ax
  110.         mov ds,ax
  111.         mov al,byte ptr ds:[46CH]
  112.       up2886:mov ah,byte ptr ds:[46CH]
  113.         cmp ah,al
  114.         je up2886
  115.       inc9823: inc dx
  116.         mov cx,4*138
  117.       here6: loop here6
  118.         mov al,byte ptr ds:[46CH]
  119.         cmp al,ah
  120.         je inc9823
  121.         pop ds
  122.         call overmusic
  123.  
  124. music label word
  125. ;----------------------------------------------------------------------;
  126.         dw e2,n4d   ;Gavotte I from Bach's Orch. Suite #1 in C         ;
  127.         dw f2,n4s                                                      ;
  128.         dw g2,n4d                                                      ;
  129.         dw a2,n8d, f2,n8d                                              ;
  130.         dw g2,n4d, c2,n4s, a2,n4d, f2,n4s, d2,n4d, e2,n4s, f2,n4d      ;
  131.         dw g2,n8d,e2,n8d,f2,n8d,d2,n8d,g2,n4s                          ;
  132.         dw  f2,n16,e2,n16,f2,n16,e2,n16s   ;trill on e2,n4d            ;
  133.         dw d2,n8,c2,n8d                                                ;
  134.         dw f2,n8,e2,n8,d2,n8,c2,n8d                                    ;
  135.         dw d2,n4d,e2,n8d,c2,n8d,d2,n8d,b1,n8d,e2,n4s                   ;
  136.         dw  d2,n16,c2,n16,d2,n16,c2,n16s   ;trill on c2,n4d            ;
  137.         dw b1,n8,a1,n8d                                                ;
  138.         dw d2,n8,c2,n8,b1,n8,a1,n8d                                    ;
  139.         dw d2,n4d,g2,n4s                                               ;
  140.         dw  c2,n16,b1,n16,c2,n16,b1,n16s   ;trill on b1,n4d            ;
  141.         dw a1,n8d,g1,n8s                                               ;
  142.         dw g1,n2                                                       ;
  143.                                                                        ;
  144.    ;The following line is Pop Goes the Weasel, if you prefer that.     ;
  145.         ;dw a2 ,n2s, d2 ,n4d, f2 ,n4s, e2 ,n2, c2 ,n2d                 ;
  146. ;----------------------------------------------------------------------;
  147.         dw -1
  148. overmusic: pop si     ;points to music
  149.         shl dx,1
  150.         mov word ptr ds:[offset timer2 +1-offset music+si],dx
  151.      note: lodsw
  152.         cmp ax,-1
  153.         je done
  154.         or ax,ax
  155.         je ov2            ;rest
  156.         mov cx,ds:[si]
  157.         mov bx,cx
  158.         and ch,0111111B
  159.         mov dx,cx
  160.         shr dx,1
  161.         test bh,0C0h
  162.         je ov3            ;legato if equal
  163.         test bh,80h
  164.         jne ov4           ;staccato if not equal
  165.         shr dx,1          ;else detached
  166.       ov4: sub cx,dx
  167.         call setup
  168.         call timer2
  169.         mov cx,dx
  170.         call timer2
  171.         inc si
  172.         inc si
  173.         jmp note
  174.       ov3: call setup
  175.       ov2: push ax
  176.         lodsw
  177.         mov cx,ax
  178.         pop ax
  179.         call timer2
  180.         jmp note
  181. setup:  dec si
  182.         dec si
  183.         mov al,0b6H
  184.         out 43H,al
  185.         lodsb
  186.         out 42H,al
  187.         lodsb
  188.         out 42H,al
  189.         in al,61H
  190.         or al,3
  191.         out 61H,al
  192.         ret
  193. timer2: mov bx,0000     ;will be filled in with a number
  194.       decbx: dec bx
  195.         jg decbx
  196.         loop timer2
  197.         and al,0FDH     ;turn off speaker
  198.         out 61H,al
  199.     done: ret
  200. cseg ends
  201. end begin
  202.